package com.group.itms.routes.utils;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.j256.ormlite.dao.CloseableIterator;
import com.j256.ormlite.dao.ForeignCollection;

public class Convert {
	
	public static <T> List<T> toList(ForeignCollection<T> collection) {
		List<T> list = new ArrayList<T>();
		if (collection != null) {
			CloseableIterator<T> iterator = collection.closeableIterator();
			try {
				while (iterator.hasNext()) {
					list.add(iterator.next());
				}
			} finally {
				try {
					iterator.close();
				} catch (SQLException e) {
					// ignored
				}
			}
		}
		return list;
	}
}
